package com.foreverwin.jzymes.report.nc.service.impl;

import com.foreverwin.jzymes.common.domain.NcData;
import com.foreverwin.jzymes.common.mapper.NcDataAdviceMapper;
import com.foreverwin.jzymes.report.nc.mapper.NcDataReportMapper;
import com.foreverwin.jzymes.report.nc.service.ICarrierNCReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class CarrierNCReportServiceImpl implements ICarrierNCReportService {
    @Autowired
    NcDataReportMapper ncDataReportMapper;

    /**
     * 不良记录报表
     *
     * @param jsonMap
     * @return
     * */
    @Override
    public List<NcData> searchCarrierNCReport(Map< String , Object > jsonMap ){
        String site = (String)jsonMap.get("site");
        String itemBo = (String)jsonMap.get("itemBo");
        String resrce = (String) jsonMap.get("resrce");
        String ncCode = (String)jsonMap.get("ncCode");

        Date startDate = null;
        Date endDate = null ;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        if ( (String) jsonMap.get( "startDate" ) != "" ){
            try {
                startDate = sdf.parse( (String) jsonMap.get( "startDate" ) );
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }

        if ( (String) jsonMap.get( "endDate" ) != "" ){
            try {
                endDate = sdf.parse( (String) jsonMap.get( "endDate" ) );
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }

      List<NcData> ncDatas =  ncDataReportMapper.selectNcDataByReport( site,itemBo,resrce,ncCode,startDate,endDate );

        return ncDatas;
    }

}
